package com.cloudlead.fleetAction.service.impl;

import com.cloudlead.commonData.service.BaseDockService;
import com.cloudlead.commonData.service.RegionService;
import com.cloudlead.commonData.vo.BaseDock;
import com.cloudlead.commonData.vo.BaseDoor;
import com.cloudlead.commonData.vo.Region;
import com.cloudlead.fleetAction.service.BaseDockEditSer;
import com.cloudlead.fleetService.vo.BaseDockCreateVo;
import com.cloudlead.fleetService.vo.BaseDockVo;
import com.cloudlead.fleetService.vo.RegionVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by wyj on 2015/8/18.
 */
@Service
public class BaseDockEditSerImpl implements BaseDockEditSer {

    @Autowired
    BaseDockService baseDockService;

    @Autowired
    RegionService regionService;

    @Override
    /**
     * 码头创建
     */
    public String createDock(BaseDockCreateVo cvo) {
        BaseDock bd = new BaseDock();
            BeanUtils.copyProperties(cvo, bd);//拷贝类型相同属性
        /**
         * 类型不同属性
         */
        baseDockService.create(bd);
        return "success";
    }

    @Override
    /**
     * 码头列表查询
     */
    public List<BaseDockVo> findAllDock(BaseDockVo vo) {
        BaseDock bd=new BaseDock();
        BeanUtils.copyProperties(vo, bd);//类型转换
        List<BaseDock> lbd=baseDockService.list(bd,null);
        List<BaseDockVo> lbdvo = new ArrayList<BaseDockVo>();
        for(Iterator<BaseDock> it = lbd.iterator();it.hasNext();) {//遍历
            BaseDockVo bdv=new BaseDockVo();
            BaseDock bdr=it.next();
            BeanUtils.copyProperties(bdr, bdv);//类型转换
            /*RegionVo rv =new RegionVo();
            bdv.setBaseCity(rv);*/
            lbdvo.add(bdv);
        }
        return lbdvo;
    }

    @Override
    /**
     * 码头删除
     */
    public String delDock(String id) {
        BaseDock bd= baseDockService.view(id);
        if(bd!=null){
            baseDockService.delete(id);
        }else
            return "error ID";
        return "success";
    }

    public String editDock(BaseDockVo vo){
        BaseDock bv=new BaseDock();
        BeanUtils.copyProperties(vo, bv);
        baseDockService.update(bv);
        return "success";
    }

    public String addDock(BaseDockVo vo){
        BaseDock bv=new BaseDock();
        BeanUtils.copyProperties(vo, bv);
        baseDockService.create(bv);
        return "success";
    }
}
